﻿import NotesList from './data/notes';

import {
  GraphQLList,
  GraphQLObjectType,
  GraphQLSchema,
  GraphQLString,
  GraphQLInt,
  GraphQLFloat,
  GraphQLEnumType,
  GraphQLNonNull,
  GraphQLInterfaceType
} from 'graphql';

const Note = new GraphQLObjectType({
	name: 'Note',
	description: '文章类型',
	fields: () => ({
		_id: {type: GraphQLString},
		title: {type: GraphQLString},
		content: {type: GraphQLString}
	}),
	args: {
		id: {type: GraphQLString}
	},
	resolve: function(source, {id}){
		if(id){
			return NotesList.filter(note => note.id === id)
		}else{
			return NotesList
		}
	}
});
const Mutation = new GraphQLObjectType({
	name: 'NoteMutations',
	fields: {
		createNote: {
			type: Note,
			description: '创建note',
			args: {
				_id: {type: new GraphQLNonNull(GraphQLString)},
				title: {type: new GraphQLNonNull(GraphQLString)},
				content: {type: new GraphQLNonNull(GraphQLString)},
			},
			resolve: function(source,{...args}){
				let note = args;
				var alreadyExists = (() => {
					for(let n in NotesList){
						if(n._id === note._id){
							return n
						}
					}
				})()
				if(alreadyExists){
					 
				}
			}
		}
	}
})